<?php
/**
 * Free Uch Pm Check Simulation Comet
 *
 * @category   FreeUch
 * @copyright  Copyright 2009 lordharrdlee(http://www.lordharrdlee.cn)
 * @author     lordharrdlee<lordharrdlee@gmail.com>
 * @version    $Id: pmcomet.php 3 2009-10-27 09:54:35Z lordharrdlee $
 */
include_once '../common.php';
include_once S_ROOT.'./uc_client/client.php';

if($_SGLOBAL['supe_uid']) {
	set_time_limit(0);
	$filename  = getnewnoticefile($_SGLOBAL['supe_uid']);

	$lastmodif    = isset($_GET['timestamp']) ? $_GET['timestamp'] : 0;

	$currentmodif = filemtime($filename);
	$i = 1;
	while ($currentmodif <= $lastmodif)
	{
		if($i%15==0) {
			$ucnewpm = uc_pm_checknew($_SGLOBAL['supe_uid']);
			if($ucnewpm != 0) {
				updatetable('space', array('newpm'=>$ucnewpm), array('uid'=>$_SGLOBAL['supe_uid']));
			}
		}
		usleep(10000);
		clearstatcache();
		$currentmodif = filemtime($filename);
		$i++;
	}

	$query = $_SGLOBAL['db']->query("SELECT notenum,pokenum,addfriendnum,mtaginvitenum,eventinvitenum,myinvitenum FROM ".tname('space')." WHERE uid = '{$_SGLOBAL['supe_uid']}'");
	$nums = $_SGLOBAL['db']->fetch_array($query);
	$response = array();
	$response['msg']       = $nums;
	$response['timestamp'] = $currentmodif;
	echo json_encode($response);
	flush();
}

exit;